package com.zhanggm.springcloud.repair.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhanggm.springcloud.common.ResponseResult;
import com.zhanggm.springcloud.common.model.RepairModel;
import com.zhanggm.springcloud.repair.api.CarApi;
import com.zhanggm.springcloud.repair.service.ICarRepairRecordService;
import com.zhanggm.springcloud.repair.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 车辆维修记录表 前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2020-12-12
 */
@RestController
@RequestMapping("/repair")
public class CarRepairRecordController {

    @Autowired
    private ICarRepairRecordService iCarRepairRecordService;

    @Autowired
    private CarApi carApi;

    @Autowired
    private IPersonService iPersonService;

    @GetMapping("getPageInfo")
    public ResponseResult getPageInfo(RepairModel repairModel,
                                      @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        Page pageInfo = iCarRepairRecordService.getPageInfo(repairModel, pageNum, pageSize);
        return ResponseResult.success(pageInfo);
    }

    @GetMapping("initData")
    public ResponseResult initData(){
        Map<String,Object> resultMap = new HashMap<>();
        //车辆列表
        resultMap.put("personList",iPersonService.list());
        //维修人员列表
        resultMap.put("carList",carApi.listAll());
        return ResponseResult.success(resultMap);

       /* RepairModel repairModel = new RepairModel();
        repairModel.setCarList(carApi.listAll());
        repairModel.setPersonList(iPersonService.list());
        return ResponseResult.success(repairModel);*/
    }

}
